package com.tanxiaoyao.wecon.net;

import java.io.IOException;
import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.tanxiaoyao.wecon.app.UpdateInfo;

import android.util.Log;
import android.util.Xml;

public class UpdateInfoParser {

	public static UpdateInfo getUpdateInfo(InputStream is) throws XmlPullParserException, IOException{
		XmlPullParser parser = Xml.newPullParser();   //取得XmlPullParser解析器，准备对XML进行解析
		parser.setInput(is, "UTF-8");
		Log.d("tanxiaoyao", "setinput : " + "setinputend");
		UpdateInfo updateInfo = UpdateInfo.getUpdateInfo();    //实例化UpdateInfo对象
		int type = parser.getEventType();
		Log.d("tanxiaoyao", "getEventType : " + type);
		while(type != XmlPullParser.END_DOCUMENT){
			Log.d("tanxiaoyao", "type-notend : " + type);
			if(type==XmlPullParser.START_TAG){
				Log.d("tanxiaoyao", "type-start : " + type);
				Log.d("tanxiaoyao", "getname : " + parser.getName());
				if("version".equals(parser.getName())){
					String version = parser.nextText();
					Log.d("tanxiaoyao", "type-version : " + version);
					updateInfo.setVersion(version);
				}else if("description".equals(parser.getName())){
					String description = parser.nextText();
					Log.d("tanxiaoyao", "type-description : " + description);
					updateInfo.setDescription(description);
				}else if("apkurl".equals(parser.getName())){
					String apkurl = parser.nextText();
					Log.d("tanxiaoyao", "type-apkurl : " + apkurl);
					updateInfo.setApkurl(apkurl);
				}else if("apksize".equals(parser.getName())){
					String apksize = parser.nextText();
					Log.d("tanxiaoyao", "type-apksize : " + apksize);
					updateInfo.setApksize(apksize);
				}
			}
			type = parser.next();
		}
		return updateInfo;
	}
}
